var headBank;
var provinceCode;
var cityCode;
var bankName;
var branchBankName;
var headbankName;


function getBankData() {
    var reg = /[a-zA-Z']/g;
    var bankName1 = $("#bankName1").val().replace(reg, "");
    if (bankName1 != bankName) {
        $("#box1").html('');
        console.warn($("#bankName1").val() + "   " + bankName1 + "     " + bankName);
        bankName = bankName1;
    } else
        return;

    if (head_bank_data == null) {
        $.ajax({
            url: GV.ctxPath + "bank/getBankData?bankName=" + bankName,
            type: "get",
            dataType: "json",
            success: function (data) {
                head_bank_data = data;
            }
        });
    }
    handlerHeadBankData(head_bank_data,bankName);
}



function handlerBranchData(data,branchBankName) {
    $("#box2").html('');
    var map = data;
    var html = "";
    for (var key in map) {
        if(map[key].indexOf(branchBankName)== -1)
            continue;
        console.log("属性：" + key + ",值：" + map[key]);
        var select = $("#brcnchBank_select_div").html().replace("select_content", "<span id= " + key + ">" + map[key] + "</span>" + "<input type=\"radio\" id=\"branchBankCode1\" name=\"branchBankCode1\" value=\"" + key + "\">");
        html += select;
    }
    $("#box2").html(html);
}


function handlerHeadBankData(data,bankName) {
    var map = data;
    var html = "";
    for (var key in map) {
        if(map[key].indexOf(bankName)== -1)
            continue;
        console.log("属性：" + key + ",值：" + map[key]);
        var select = $("#bank_select_div").html().replace("select_content", "<span id= " + key + ">" + map[key] + "</span>" + "<input type=\"radio\" id=\"bankCode1\" name=\"bankCode1\" value=\"" + key + "\">");
        html += select;
    }
    $("#box1").html(html);
}

function getBranchData() {
    console.log($("#bankCode").val()+"   "+$("#bankProvinceCode").val()+"   "+  $("#bankCityCode").val() +"   "+ $("#branchBankName1").val());

//    if ($("#bankCode").val() == headbankName && provinceCode == $("#bankProvinceCode").val() && cityCode == $("#bankCityCode").val() && branchBankName == $("#branchBankName1").val())
//        return;
    headbankName = $("#bankCode").val();
    provinceCode = $("#bankProvinceCode").val();
    cityCode = $("#bankCityCode").val();
    branchBankName = $("#branchBankName1").val();

    if (headbankName == "" && provinceCode == "" && cityCode == "" && bankName == "")
        return;
    if (branch_bank_data == null){
        $.ajax({
            url: GV.ctxPath + "bank/queryBankBranch",
            type: "GET",
            async: false,
            data: {
                "headBank": headbankName,
                "provinceCode": provinceCode,
                "cityCode": cityCode,
                "bankName": branchBankName
            },
            dataType: "json",
            success: function (data) {
                branch_bank_data = data;
            }
        });
    }
    handlerBranchData(branch_bank_data,branchBankName);
}


